package com.godofgamblers.hotelmanagementsystem.service.imp;

import com.godofgamblers.hotelmanagementsystem.mapper.UserMapper;
import com.godofgamblers.hotelmanagementsystem.mapper.User_levelMapper;
import com.godofgamblers.hotelmanagementsystem.pojo.User;
import com.godofgamblers.hotelmanagementsystem.pojo.User_Level;
import com.godofgamblers.hotelmanagementsystem.service.UserService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: 伴你时光尽头
 * @Date: 2019/10/18 15:41
 */
@Data
@Service
public class UserServiceImp implements UserService {


    @Autowired
    private UserMapper userMapper;
    @Autowired
    private User_levelMapper user_levelMapper;

    /**
     * 查询：
     * 查询所有软删除状态为1存在的数据 封装成user类型的额集合返回  非用户
     *
     * @return user类型的额集合
     */
    @Override
    public List<User> showAllItem() {
        return userMapper.showAllItem();
    }

    /**
     * 查询：
     * 根据手机号码查询user
     *
     * @param user 封装了user_phone的user对象
     * @return 查到的数据行各字段封装成的user对象
     */
    @Override
    public User searchUser(User user) {
        return userMapper.searchUser(user);
    }

    /**
     * 查询：
     * 根据账号查询user
     *
     * @param user 封装了user_account的user对象
     * @return 查到的数据行各字段封装成的user对象
     */
    @Override
    public User searchUserByAccount(User user) {
        return userMapper.searchUserByAccount(user);
    }

    @Override
    public Map<String, Object> checkUserState(String account) {
        //新建一个map用于储存查询信息
        Map<String, Object> result = new HashMap<String, Object>();
        //根据账号查询用户id
        Integer checkUser_id = userMapper.findUser_idByAccount(account);
        //判断账号是否存在
        if (checkUser_id == null) {
            //将检查结果存放进map中返回
            String User_id = "账号不存在!";
            result.put("checkResult", User_id);
            return result;
        }
        //通过用户id查询会员积分
        int userCredit = userMapper.findUserCreditByUser_id(checkUser_id);
        //通过积分查询会员等级、折扣
        User_Level user_level = user_levelMapper.findDiscountAndNameByCredit(userCredit);
        //将会员等级及折扣信息存放进map中返回
        result.put("User_id", checkUser_id);
        result.put("level_name", user_level.getLevel_name());
        result.put("level_discount", user_level.getLevel_discount());
        return result;

    }

    /**
     * 添加用户头像
     * @param user
     */
    @Override
    public void setHeadPicture(User user) {
        userMapper.setHeadImage(user);
    }
    @Override
    public void updateUserWallet(User user) {
        userMapper.updateUserWallet(user);
    }

    @Override
    public User findUserByUserid(Integer user_id) {
        return userMapper.findUserByUserid(user_id);
    }

    @Override
    public String getUserImage(Integer user_id) {
        return userMapper.findUser_ImageById(user_id);
    }

    @Override
    public User findUserByAccount(String user_account) {
        return userMapper.findUserByUserAccount(user_account);
    }

    @Override
    public User findUserByPhone(String user_phone) {
        return userMapper.findUserByUserPhone(user_phone);
    }

    @Override
    public User findUserByAccount_Phone(User user) {
        return userMapper.findUserByAccount_phone(user);
    }

    @Override
    public int register(User user) {
        return userMapper.register(user);
    }

    @Override
    public int updateByUser_account(User user) {
        return userMapper.updateByUser_Account(user);
    }

    @Override
    public int addUid(User user) {
        return userMapper.addUid(user);
    }



}
